package com.iot08.api.controller;

import com.iot08.api.annotation.CheckAppSign;
import com.iot08.api.controller.base.BaseController;
import com.iot08.api.response.VipPromptInfoResp;
import com.iot08.api.service.*;
import com.iot08.api.vo.request.*;
import com.iot08.api.vo.request.base.BaseAccountReqVO;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author cwj
 * @description
 * @date 2024/12/28 18:14
 **/
@Slf4j
@RestController
@RequestMapping("getway/vipMember")
public class VipMemberController extends BaseController {

    @Resource
    private VipMemberService vipMemberService;

    @Resource
    private VipPrivilegeService vipPrivilegeService;

    @Resource
    private VipPromptInfoService vipPromptInfoService;

    @Resource
    private PayOrderInfoService payOrderInfoService;

    @Resource
    private ProductInfoService productInfoService;

    @PostMapping("/createOrder")
    //@CheckAppSign
    public ResponseMap createOrder(@Validated @RequestBody CreatePaymentReqVO vo){
        return payOrderInfoService.createOrder(vo.getBodyForm());
    }

    @PostMapping("/queryOrder")
    //@CheckAppSign
    public ResponseMap queryPayOrderInfoService(@Validated @RequestBody QueryOrderReqVo vo){
        return payOrderInfoService.queryPayOrderInfoService(vo.getBodyForm());
    }


    /**
     * @description 开通会员，保存会员信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/29 11:17
     **/
    @PostMapping("/openVip")
    //@CheckAppSign
    public ResponseMap openVipMember(@Validated @RequestBody VipMemberOpenReqVo vo) {
        return vipMemberService.openVipMember(vo.getBodyForm());
    }

    /**
     * @description 查询会员信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/29 14:14
     **/
    @PostMapping("/query")
    @CheckAppSign
    public ResponseMap queryVipMember(@Validated @RequestBody QueryVipMemberReqVo vo){
        return  vipMemberService.queryVipMember(vo.getBodyForm());
    }


    /**
     * @description 查询会员服务协议
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/29 14:01
     **/
    @GetMapping("/protocol")
    public ResponseMap queryVipMemberServiceProtocol(@Validated BaseAccountReqVO vo){
        String protocolUrl = vipMemberService.queryVipMemberServiceProtocol();
        ResponseMap res = ResponseMap.success();
        res.put("protocolUrl", protocolUrl);
        return res;
    }


    /**
     * @description 查询会员的特权信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/29 14:18
     **/
    @GetMapping("/privilege")
    public ResponseMap queryVipPrivilegePromptInfo(@Validated BaseAccountReqVO vo){
        return vipPrivilegeService.queryVipPrivilege();
    }


    /**
     * @description 查询产品信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/31 9:00
     **/
    @GetMapping("/productInfo")
    public ResponseMap queryProductInfo(@Validated BaseAccountReqVO vo){
        //获取版本信息
        VersionVo versionVo = obtainVersionInfo(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
        return productInfoService.queryProductInfo(versionVo,vo.getOpenid());
    }


    /**
     * @description 添加Vip权限信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/30 18:14
     **/
    @PostMapping("/addVipPrililege")
    public ResponseMap addVipPrililegeInfo(@Validated AddVipPrililegeReqVo vo){
        return vipPrivilegeService.addVipPrililegeInfo(vo);
    }

    /**
     * @description 编辑会员特权信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/2/15 11:36
     **/
    @PostMapping("/editVipPrililege")
    public ResponseMap editVipVipPrililege(@Validated EditVipPrililegeReqVo vo){
        return vipPrivilegeService.editVipVipPrililege(vo);
    }
    
    /**
     * @description 查询温馨提示，会员协议信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/31 8:50
     **/
    @GetMapping("/promptInfo")
    public ResponseMap queryVipPromptInfo(@Validated BaseAccountReqVO vo){
        List<VipPromptInfoResp> promptInfoResps = vipPromptInfoService.queryVipPromptInfo();
        String protocolUrl = vipMemberService.queryVipMemberServiceProtocol();
        ResponseMap res = ResponseMap.success();
        res.put("protocolUrl", protocolUrl);
        res.put("vipPromptInfos",promptInfoResps);
        return res;
    }


    /**
     * @description 添加Vip提示信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/30 18:14
     **/
    @PostMapping("/addVipPrompt")
    public ResponseMap addVipPromptInfo(@Validated AddVipPromptInfoReqVo vo){
        return vipPromptInfoService.addVipPromptInfo(vo);
    }


    /**
     * @description 添加产品信息
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/30 18:20
     **/
    @PostMapping("/addProductInfo")
    public ResponseMap addProductInfo(@Validated AddProductInfoReqVo vo){
        return productInfoService.addProductInfo(vo);
    }


    /**
     * @description 更新
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/31 14:09
     **/
    @PostMapping("/editProductInfo")
    public ResponseMap editProductInfo(@Validated AddProductInfoReqVo vo){
        return productInfoService.editProductInfo(vo);
    }


    /**
     * @description 检查充值会员是否到期，非充值会员则核对是否需要进行首次充值优惠提醒
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/4/22 8:54
     **/
    @GetMapping("/checkVipExpire")
    public ResponseMap checkVipExpire(@Validated BaseAccountReqVO vo){
        return vipMemberService.checkVipExpire(vo.getOpenid());
    }

}
